<?php 
/**
 * 
 * @author hushuai
 *
 */
class ProductModel extends Model {
	
	public function mb_str_split( $string ) {
		return preg_split('/(?<!^)(?!$)/u', $string );
	}
	
	//门店列表查询无分页
	public function outletView() {
		$json = sendRest("BDC/Outlet/view");
		return $json['data'];
	}
	//菜品分类列表查询无分页
	public function sortView($map) {
		
		$json  = sendRest("RMS/Product/sortView",$map);
		return $json['data'];
	}
	//根据门店编号查询门店详情
	public function outletDetail($map) {
	
		$json  = sendRest("BDC/Outlet/detail",$map);
		return $json['data'];
	}
	//根据门店编号查询门店详情
	public function getSortByOutlet($map) {
	
		$json = sendRest("RMS/Product/sort",$map);
		return $json['data'];
	}
	//根据门店编号查询门店详情
	public function getSortDetail($map) {
	
		$json = sendRest("RMS/Product/sortFind",$map);
		return $json['data'];
	}
	//根据父类查询子类
	public function getSub($map) {
	
		$json = sendRest("RMS/Product/selSub",$map);
		return $json['data'];
	}
	//根据菜品id查询菜品详情
	public function dishesDetail($map) {
		
		$json = sendRest("RMS/Product/detail",$map);
		return $json['data'];
	}
	
	/**
	 * 导出库存商品领取记录
	 */
	public function exportGetList($map){
		
		//领取记录
		$json = sendRest("RMS/Product/drinkGetView",array('where'=>$map));
		
		//地址数据字典
		$dict_address = sendRest("BDC/Outlet/dictAddress");
		
		header("Content-type:application/octet-stream");
		header("Accept-Ranges:bytes");
		header("Content-type:application/vnd.ms-excel");
		header("Content-Disposition:attachment;filename=库存商品领取记录".date("Y-m-d").".xls");
		header("Pragma: no-cache");
		header("Expires: 0");

		$tag0  = iconv("UTF-8", "GB2312",'序号');
		$tag1  = iconv("UTF-8", "GB2312",'时间');
		$tag2  = iconv("UTF-8", "GB2312",'城市');
		$tag3  = iconv("UTF-8", "GB2312",'领取人');
		$tag4  = iconv("UTF-8", "GB2312",'商品编号');
		$tag5  = iconv("UTF-8", "GB2312",'商品名称');
		$tag6  = iconv("UTF-8", "GB2312",'领取数量');
		$tag7  = iconv("UTF-8", "GB2312",'领取时间');
		$tag8  = iconv("UTF-8", "GB2312",'备注');
		
		echo "$tag0\t$tag1\t$tag2\t$tag3\t$tag4\t$tag5\t$tag6\t$tag7\t$tag8\n";
		
		$i = 1;
		foreach($json['data'] as $key=>$val){
			
			//用户资料
			$userid = $val['userid'];
			$user   = M('Admin')->find($userid);
			$city   = $dict_address['data']['zh-cn']['array'][$val['city']][0];
			
			$sort      = iconv("UTF-8", "GB2312", $i);
			$time      = iconv("UTF-8", "GB2312", date("ymd",$val['addtime']));
			$city      = iconv("UTF-8", "GB2312", $city);
			$realname  = iconv("UTF-8", "GB2312", $user['realname']);
			$drink_num = iconv("UTF-8", "GB2312", $val['drink_num']);
			$title     = iconv("UTF-8", "GB2312", $val['title']);
			$num       = iconv("UTF-8", "GB2312", $val['num']);
			$content   = iconv("UTF-8", "GB2312", $val['content']);
			$addtime   = iconv("UTF-8", "GB2312", date("Y-m-d H:i:s",$val['addtime']));
			
			$i++;
			echo "$sort\t$time\t$city\t$realname\t$drink_num\t$title\t$num\t$addtime\t$content\n";
		}
	}
	
}
?>